package net.area80.components
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import net.area80.components.skin.ABScrollbarSkin;
	import net.area80.utils.DrawingUtils;
	
	import org.osflash.signals.Signal;
	
	
	public class UITableList extends Sprite
	{
		protected var listWidth:uint;
		protected var itemWidth:uint;
		protected var itemHeight:uint;
		
		protected var container:Sprite;
		protected var itemList:Vector.<UIListItem>;
	
		protected var col:uint;

		
		public function UITableList (itemWidth:uint, itemHeight:uint,col:uint)
		{
			super();
			
			this.col = col;
			this.itemWidth = itemWidth;
			this.itemHeight = itemHeight;
			
			this.listWidth =  itemWidth*col;
			
			container = new Sprite();
			addChild(container);
			
			container.cacheAsBitmap = true;
			
		}

		public function get length ():uint {
			return (itemList) ? itemList.length : 0;
		}
		public function getItemAt (id:uint):UIListItem {
			return (itemList) ?  itemList[id] : null;
		}
		public function getItemList ():Vector.<UIListItem> {
			return itemList;
		}
		public function addItem (u:UIListItem):void {
			if(!itemList) itemList = new Vector.<UIListItem>;
			u.init(this);
			u.cacheAsBitmap = true;
			container.addChild(u);
			itemList.push(u);
			positionItem();
		}
		protected function positionItem ():void {
			var count:uint = 0;
			if(itemList) {
				for(var i:uint =0;i<itemList.length;i++) {
					if(itemList[i].visible) {
						itemList[i].x = itemWidth*(count%col);
						itemList[i].y = itemHeight*Math.floor(count/col);
						count++;
					}
				}
			}
			
		}
		
	}
}